﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TSL_Tools.XMLTools;
using System.Xml;
using System.Drawing;
using System.ComponentModel;

namespace ReportingAppConfig
{
    public class PlotColors
    {
        #region -- Public Properties ----------------------------------------------------
        public Dictionary<int, System.Drawing.Color> colorList { get; private set; }
        #endregion

        #region -- Private Properties ---------------------------------------------------
        private int currentColorIndex = 0;
        #endregion

        #region -- Constructors ---------------------------------------------------------
        public PlotColors() 
        {
            colorList = new Dictionary<int, Color>();
        }
        #endregion

        #region -- Public Methods -------------------------------------------------------
        /// <summary>
        /// Used to load the config user settings into the  <see cref="AppConfiguration"/> class settings
        /// </summary>
        public void GetConfigValues(XmlDocument xDoc)
        {
            int x = 0;
            //First build the plot colors list so it can be used going through the iterations

            XmlNode xNode = xDoc.SelectSingleNode("Configuration/PlotColors");
            {
                foreach (XmlNode xChild in xNode.SelectNodes("item"))
                {
                    System.Drawing.Color c = (System.Drawing.Color)TypeDescriptor.GetConverter(typeof(System.Drawing.Color)).ConvertFromString(xChild.Attributes["color"].Value);
                    colorList.Add(x, c);
                    x++;
                }
            }
        }

        /// <summary>
        /// Used to set the <see cref="AppConfiguration"/> class settings back into the config user settings file and then to save them.
        /// </summary>
        public void SaveConfigValues(XmlDocument xDoc)
        {
        }

        /// <summary>
        /// Gets the current color in the list and advances the list index to the next color
        /// </summary>
        /// <returns></returns>
        public Color GetCurrentColor()
        {
            Color color = colorList[currentColorIndex];
            currentColorIndex++;
            if(currentColorIndex >= colorList.Count)
            {
                currentColorIndex = 0;
            }
            return color;
        }
        #endregion

        #region -- Private Methods ------------------------------------------------------
        #endregion
    }
}
